<template>
  <el-upload
    class="avatar-uploader"
    action="http://localhost:9001/readCsv/"
    :show-file-list="false"
    :on-success="handleAvatarSuccess"
    :before-upload="beforeAvatarUpload"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  </el-upload>
  <el-button type="primary" @click="startceshi">开始测试</el-button>
  <el-table :data="tableData">
    <el-table-column prop="url" label="url"/>
    <el-table-column prop="method" label="method"/>
    <el-table-column prop="params" label="params" />
    <el-table-column prop="expect_code" label="expect_code" />
    <el-table-column prop="actual_code" label="actual_code" />
    <el-table-column prop="is_pass" label="is_pass" />
    <el-table-column prop="taskid" label="taskid" />
    <el-table-column prop="status" label="status" />
  </el-table>
</template>

<script lang="ts" setup>
import {onMounted, ref} from 'vue'
import { ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'

import type { UploadProps } from 'element-plus'
import http from "../../http";

const imageUrl = ref('')

const tableData = ref([]);
// onMounted(()=>{
//   http.get('testlist/').then(res=>{
//     console.log(res)
//     tableData.value = res.data.list
//   })
// })

const startceshi = () => {
  // http.get("readCsv/").then(res => {
  //   console.log(res)
  //
  // })
  http.get('testlist/').then(res=>{
    console.log(res)
    tableData.value = res.data.list
  })
}

const handleAvatarSuccess: UploadProps['onSuccess'] = (
  response,
  uploadFile
) => {
  imageUrl.value = URL.createObjectURL(uploadFile.raw!)
}

const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {

  return true
}
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>
